package com.example.bmiapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

    }
    val message=""

    private fun showMessage(message:String)
    {
        val alertDialog = AlertDialog.Builder(this).setMessage(message).setCancelable(false)
            .setPositiveButton(android.R.string.ok)
            { _, _ ->
                Toast.makeText(this@MainActivity, "用户点击了确定", Toast.LENGTH_SHORT).show()
            }
            .setNegativeButton(android.R.string.cancel) { _, _ ->
                Toast.makeText(this@MainActivity, "用户点击了取消", Toast.LENGTH_SHORT).show()
            }
            .create()
        alertDialog.show()
    }



    fun buSumEvent(view: View)
    {
        if(!heightText.getText().toString().trim().equals("") &&  !weightText.getText().toString().trim().equals(""))
        {
            var height=heightText.text.toString().toDouble()
            var weight=weightText.text.toString().toDouble()
            if(buttonman.isChecked||buttonwoman.isChecked)
            {
                if(buttonman.isChecked)
                {
                    var normalweight=(height-80)*0.7
                    var overweight=(weight-normalweight)/normalweight
                    if (Math.abs(overweight)<0.1)
                    {
                        showMessage("正常体重")
                    }
                    else if (Math.abs(overweight)<0.2)
                    {
                        showMessage("体重过重或过轻")
                    }
                    else if (Math.abs(overweight)<0.2)
                    {
                        showMessage("肥胖或体重不足")
                    }
                }
                if(buttonwoman.isChecked)
                {
                    var normalweight=(height-80)*0.7
                    var overweight=(weight-normalweight)/normalweight
                }
            }
            else
            {
                showMessage("请输入性别")
            }
        }
        else {
            showMessage("请输入身高或体重")
        }

    }







}